import java.time.Instant;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class Message implements Serializable {
    private static int sequence = 0;
    private int id; // 消息序号
    private int timestamp; // 时间戳
    private String tag; // 消息tag
    private String body; // 消息体

    public Message(String tag, String body) {
        this.id = ++sequence;
        // 获取当前日期和时间
        LocalDateTime currentDateTime = LocalDateTime.now();

        // 获取时间戳（以秒为单位）
        int timeStampInSeconds = (int) currentDateTime.toEpochSecond(ZoneOffset.UTC);
        this.timestamp = timeStampInSeconds;
        this.tag = tag;
        this.body = body;
    }

    public int getId() {
        return id;
    }

    public void setTimestamp(int timestamp) {
        this.timestamp = timestamp;
    }

    public int getTimestamp() {
        return timestamp;
    }

    public String getTag() {
        return tag;
    }

    public String getBody() {
        return body;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Message{" +
                "id=" + id +
                ", timestamp=" + timestamp +
                ", tag='" + tag + '\'' +
                ", body='" + body + '\'' +
                '}';
    }
}
